package com.xuecheng.auth.api;

import com.xuecheng.auth.model.po.XcUser;
import com.xuecheng.auth.service.XcUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api("用户管理接口")
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    XcUserService userService;

    @ApiOperation("保存用户")
    @PostMapping
    public XcUser saveUser(@RequestBody XcUser user){
        if(user == null){
            return null;
        }
        if(user.getId() == null){
            userService.save(user);
        }else{
            userService.updateById(user);
        }
        return userService.getById(user.getId());
    }

    @ApiOperation("开通账号")
    @PostMapping("/createAccount")
    public XcUser createAccount(Long companyId){
        return userService.createAccount(companyId);
    }
}
